package com.heima.bos.web.action.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.heima.bos.domain.Function;
import com.heima.bos.domain.User;
import com.heima.bos.service.BaseService;
import com.heima.bos.service.FunctionService;
import com.heima.bos.utils.BOSUtils;
import com.heima.bos.web.action.FunctionActionInter;
@Controller
@Scope("prototype")
public class FunctionAction extends BaseAction<Function> implements FunctionActionInter{
	@Resource
	private FunctionService functionService;
	@Override
	protected BaseService<Function> getService() {
		return functionService;
	}
	/**
	 * 加载菜单
	 */
	public String findMenu(){
		User user = (User) BOSUtils.getSession().getAttribute("user");
		List<Function> list = functionService.findMenu(user);
		String[] excludes = new String[]{"children","roles","parentFunction"};
		writeList2Json(list, excludes);
		return NONE;
	}
	/**
	 * 查询所有的权限数据返回json
	 * 功能2  为添加角色页面初始化权限列表
	 */
	public String list(){
		List<Function> functions = functionService.findAll();
		String[] excludes = new String[]{"parentFunction","code","children","roles"};
		writeList2Json(functions, excludes);
		return NONE;
	}

}
